<template>
  <div class="copy">
    <p class="backIcon" @click="$emit('closeCopy',false)"><svg-icon iconClass="back" /></p>
    <div class="copyBox">
      <img src="../../src/images/weixin.png" alt="" />
      <div class="copyTitle1">去微信粘贴给好友</div>
      <div class="copyTitle2">好友帮忙后可<span>砍大金额</span></div>
      <button
        class="copySvg"
        @click="copyWord()"
        id="btn"
        :data-clipboard-text="text"
      >
        <svg-icon iconClass="wechat" /><span>去微信粘贴</span>
      </button>
    </div>
  </div>
</template>

<script>
import Clipboard from "clipboard";
import { Toast } from "vant";
export default {
  data() {
    return {
      text:
        "此商品口令为:" +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000),
      data: []
    };
  },
  methods: {
    copyWord() {
      let clipBoard = new Clipboard("#btn");
      clipBoard.on("success", function() {
        clipBoard.destroy(); //销毁上一次的复制内容
        clipBoard = new Clipboard("#btn");
        Toast.success("复制成功");
      
      });
      clipBoard.on("error", function() {
        alert("复制失败，请手动复制");
      });
      this.data.push({
        id: +new Date(),
        value: this.text
      });
      this.updataData();
      /* setTimeout(() => { */
        /* this.$emit("closeCopy",false) */
        this.$router.push("/examine")
        
        /* }, 2000); */
      console.log( "此商品口令为:" +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000) +
        Math.random()
          .toString(36)
          .substr(2, 10000))
    },
    updataData() {
      localStorage.setItem("content", JSON.stringify(this.data));
    }
  }
};
</script>
<style lang="scss" scoped>
.copy {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 102;
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  left: 0;
  top: 0;
  .backIcon {
    width: 100%;
    height: 50px;
    padding: 0 0 200px 15px;
    color: #fff;
  }
  .copyBox {
    width: 86%;
    height: 285px;
    background: #fff;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    z-index: 102;
    border-radius: 20px;
    font-size:22px;
    img {
      display: block;
      margin: 22px auto;
    }
    .copyTitle1,
    .copyTitle2 {
      text-align: center;
      font-weight: bold;
    }
    .copyTitle2 {
      span {
        color: red;
      }
    }
    .copySvg {
      width: 76%;
      height:40px;
      text-align: center;
      margin-left: 12%;
      margin-top: 25px;
      background: #3db134;
      color: #fff;
      border: none;
      border-radius: 30px;
      line-height:40px;
      span {
        padding: 0 20px;
        font-size: 16px;
      }
    }
  }
}
</style>